package com.sinosoft.system.util.jwt;

/*import io.jsonwebtoken.Claims;
import io.jsonwebtoken.JwtBuilder;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.DatatypeConverter;

import java.security.Key;
import java.util.Date;*/


public class JwtUtil {
//	/**
//	  * 创建 jwt
//	  * @param id
//	  * @param subject
//	  * @param ttlMillis
//	  * @return
//	  * @throws Exception
//	  */
//	public  Claims parseJWT(String jsonWebToken, String base64Security){  
//        try  
//        {  
//            Claims claims = Jwts.parser()  
//                       .setSigningKey(DatatypeConverter.parseBase64Binary(base64Security))  
//                       .parseClaimsJws(jsonWebToken).getBody();  
//            return claims;  
//        }  
//        catch(Exception ex)  
//        {  
//        	ex.printStackTrace();
//            return null;  
//        }  
//    }  
//      
//    public  String createJWT(String username, int userid, String role, String issuer,  
//             long TTLMillis, String base64Security)   
//    {  
//        SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;  
//           
//        long nowMillis = System.currentTimeMillis();  
//
//        Date now = new Date(nowMillis);  
//           
//        //生成签名密钥  
//        byte[] apiKeySecretBytes = DatatypeConverter.parseBase64Binary(base64Security);  
//        Key signingKey = new SecretKeySpec(apiKeySecretBytes, signatureAlgorithm.getJcaName());  
//           
//          //添加构成JWT的参数  
//        JwtBuilder builder = Jwts.builder().setHeaderParam("typ", "JWT")
//                                        .claim("role", role)  
//                                        .claim("username", username)  
//                                        .claim("userid", userid)
//                                        .setIssuedAt(now)
//                                        .setIssuer(issuer)
//                                        .signWith(signatureAlgorithm, signingKey);  
//         //添加Token过期时间  
//        if (TTLMillis >= 0) {  
//            long expMillis = nowMillis + TTLMillis;  
//            Date exp = new Date(expMillis);  
//            builder.setExpiration(exp).setNotBefore(now);  
//        }  
//           
//         //生成JWT  
//        return builder.compact();  
//    }
//    
//    public static void main(String[] args){
////    	SignatureAlgorithm signatureAlgorithm = SignatureAlgorithm.HS256;
////    	String jwt = createJWT("name",123,"role","issuer",30*24*60*60*1000L,"asdfg");
////    	System.out.println(jwt);
////    	Claims claims = parseJWT(jwt,"asdfg");
////    	System.out.println("ID: " + claims.getId());
////    	System.out.println("Subject: " + claims.get("role"));
////    	System.out.println("Issuer: " + claims.getIssuer());
////    	System.out.println("Expiration: " + claims.getExpiration());
//    }
}  

